# -*- coding: utf-8 -*-

# 界面文件
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QMovie, QCursor
from PyQt5.QtWidgets import  QFrame, QVBoxLayout


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(900, 600)
        MainWindow.setFixedSize(MainWindow.width(), MainWindow.height())  # setFixedSize：设置固定大小
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(350, 200, 200, 50))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(15)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName("pushButton")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 900, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.retranslateUi(MainWindow)
        self.pushButton.clicked.connect(MainWindow.login_page)

        self.frame = QFrame(MainWindow)
        self.verticalLayout = QVBoxLayout(self.frame)
        self.label1 = QtWidgets.QLabel()
        self.label1.setGeometry(QtCore.QRect(220, 220, 500, 50))
        self.label1.setTextFormat(QtCore.Qt.AutoText)
        self.label1.setAlignment(QtCore.Qt.AlignCenter)
        self.label1.setObjectName("label1")
        self.verticalLayout.addWidget(self.label1)
        self.frame.setVisible(False)

        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):   #retranslateUi：重新设计
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "标准计划删除工具"))
        self.pushButton.setText(_translate("MainWindow", "登录直通车账号"))

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(900, 600)
        font = QtGui.QFont()
        font.setFamily("楷体")
        font.setPointSize(20)
        Form.setFont(font)
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(300, 200, 121, 41))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(25)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")

        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(410, 205, 111, 41))
        self.label_2.setFont(font)
        self.label_2.setText("")
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
        self.label_2.setObjectName("label_2")
        self.gif = QMovie('../rely/icons/loading1.gif')
        self.label_2.setMovie(self.gif)
        self.gif.start()


        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "标准计划删除工具"))
        self.label.setText(_translate("Form", "采集中"))

class Ui_OptionWindow(object):
    def __init__(self):
        self.radioButton_list = []  # 单选框元素对象列表


    def setupUi(self, MainWindow, plan_info_dic):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(900, 600)
        MainWindow.setFixedSize(MainWindow.width(), MainWindow.height())  # setFixedSize：设置固定大小
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(530, 420, 291, 101))
        font = QtGui.QFont()
        font.setFamily("楷体")
        font.setPointSize(25)
        font.setBold(True)
        font.setUnderline(False)
        font.setWeight(75)
        font.setKerning(True)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setObjectName("pushButton_2")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setGeometry(QtCore.QRect(10, 10, 450, 600))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(20)
        self.groupBox.setFont(font)
        self.groupBox.setObjectName("groupBox")
        self.scrollArea = QtWidgets.QScrollArea(self.groupBox)
        self.scrollArea.setEnabled(True)
        self.scrollArea.setGeometry(QtCore.QRect(0, 44, 450, 470))
        self.scrollArea.setLineWidth(1)
        self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.scrollArea.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
        self.scrollArea.setWidgetResizable(False)
        self.scrollArea.setObjectName("scrollArea")
        self.scrollAreaWidgetContents = QtWidgets.QWidget()

        num = len(plan_info_dic)
        high = num * 20.5 if num > 12 else 200
        high = high*10
        len_max = 0
        for i in plan_info_dic:
            l = len(i)
            len_max = l if l > len_max else len_max
        wide = int(310 / 25 * len_max + 20) * 10
        print(147,wide)
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, wide, high))
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
        self.widget = QtWidgets.QWidget(self.scrollAreaWidgetContents)
        self.widget.setGeometry(QtCore.QRect(0, 0, wide, high))
        self.widget.setObjectName("widget")
        self.scrollArea.setWidget(self.scrollAreaWidgetContents)

        for i in range(1, len(plan_info_dic) + 1):  # 动态创建复选框
            exec('self.radioButton_{} = QtWidgets.QRadioButton(self.widget)'.format(i))
            # exec('self.radioButton_{}.setGeometry(QtCore.QRect(15, {}, 3000, 25))'.format(i, (i - 1) * 20 - 30))
            exec('self.radioButton_{}.setGeometry(QtCore.QRect(15, {}, 3000, 25))'.format(i, 20*i-10))
            exec("font = QtGui.QFont()")
            exec("font.setPointSize(12)")
            exec("self.radioButton_{}.setFont(font)".format(i))
            exec('self.radioButton_{}.setObjectName("radioButton_{}")'.format(i, i))
            exec('self.radioButton_list.append(self.radioButton_{})'.format(i))  # 添加单选框控件

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 900, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow, plan_info_dic)
        self.pushButton_2.clicked.connect(MainWindow.delete_data)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)



    def retranslateUi(self, MainWindow, plan_info_dic):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "标准计划删除工具"))
        self.pushButton_2.setText(_translate("MainWindow", "点击删除计划"))
        self.groupBox.setTitle(_translate("MainWindow", "请勾选要删除的计划"))
        # 动态设置radioButton文本信息
        i = 1
        for plan in plan_info_dic:
            exec('self.radioButton_{}.setText(_translate("MainWindow", "{}"))'.format(i, plan))
            i += 1
